package com.kunteng.ynhxksh.controller;

import com.kunteng.ynhxksh.entity.T_COMPANY_INFORMATION_VO;
import com.kunteng.ynhxksh.entity.T_POS_MANAGE_VO;
import com.kunteng.ynhxksh.service.YCYJService;
import com.kunteng.ynhxksh.util.ResultMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created By ShiYun with IntelliJ IDEA on 2018/4/2 10:28
 *
 * @author: ShiYun
 * @Email: 515867726@qq.com
 * @Date: 2018/4/2
 * To change this template use File | Settings | File Templates.
 */
@Api(tags = "异常预警接口")
@RestController
@RequestMapping("/ycyj")
public class YCYJController {

    Logger logger = LoggerFactory.getLogger(YCYJController.class);

    @Autowired
    private YCYJService ycyjService;

    @ApiOperation(value = "最近N天无交易商户", notes = "根据交易获取无交易商户")
    @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", required = true, paramType = "query")
    @RequestMapping(value = "/dateNoJY", method = RequestMethod.GET)
    @ResponseBody
    public ResultMsg dateNoJY(@RequestParam String date) {
        logger.info("dateNoJY {}", date);
        JSONObject object = new JSONObject();
        try {
            List<T_COMPANY_INFORMATION_VO> list = ycyjService.fingByShopRqAndJye(date);
            object.put("num", list.size());
            object.put("company", list);
            return ResultMsg.msg(0, "查询成功", object);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultMsg.msg(-1, "系统异常", e.getLocalizedMessage());
        }
    }

    @ApiOperation(value = "最近N天无开票商户", notes = "根据交易获取无开票商户")
    @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", required = true, paramType = "query")
    @RequestMapping(value = "/dateNoKP", method = RequestMethod.GET)
    @ResponseBody
    public ResultMsg dateNoKP(@RequestParam String date) {
        logger.info("dateNoKP {}", date);
        JSONObject object = new JSONObject();
        try {
            List<T_COMPANY_INFORMATION_VO> list = ycyjService.fingByShopRqAndKpl(date);
            object.put("num", list.size());
            object.put("company", list);
            return ResultMsg.msg(0, "查询成功", object);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultMsg.msg(-1, "系统异常", e.getLocalizedMessage());
        }
    }

    @ApiOperation(value = "最近N天未上线支付设备数", notes = "根据pos最后一次上线时间")
    @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", required = true, paramType = "query")
    @RequestMapping(value = "/dateOfflinePOS", method = RequestMethod.GET)
    @ResponseBody
    public ResultMsg dateOfflinePOS(@RequestParam String date) {
        logger.info("dateOfflinePOS {}", date);
        JSONObject object = new JSONObject();
        try {
            List<T_POS_MANAGE_VO> list = ycyjService.findByOfflinePOS(date);
            object.put("num", list.size());
            object.put("company", list);
            return ResultMsg.msg(0, "查询成功", object);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultMsg.msg(-1, "系统异常", e.getLocalizedMessage());
        }
    }

    @ApiOperation(value = "最近N天开票额大于交易额商户", notes = "根据开票额和交易额获取商户")
    @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", required = true, paramType = "query")
    @RequestMapping(value = "/dateKpeGtJye", method = RequestMethod.GET)
    @ResponseBody
    public ResultMsg dateKpeGtJye(@RequestParam String date) {
        logger.info("dateKpeGtJye {}", date);
        JSONObject object = new JSONObject();
        try {
            List<T_COMPANY_INFORMATION_VO> list = ycyjService.fingByShopRqAndKpeGtJye(date);
            object.put("num", list.size());
            object.put("company", list);
            return ResultMsg.msg(0, "查询成功", object);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultMsg.msg(-1, "系统异常", e.getLocalizedMessage());
        }
    }
}
